var http = require('http')

var sendPush = function (from,to,data) {  
  
    var data = {
        ty:"nomal",
        from:from,
        to:[to],
        data:data
    }
  
    data = JSON.stringify(data);  
    console.log(data);  
    var opt = {  
        method: "POST",  
        host: "192.168.1.105",  
        port: 3333,
        path: "/push",  
        headers: {
            "Content-Type": 'application/json;charset=utf-8',  
            "Content-Length": Buffer.byteLength(data,'utf8')
        }  
    };
  
    var req = http.request(opt, function (serverFeedback) {  
        if (serverFeedback.statusCode == 200) {  
            var body = "";  
            serverFeedback.on('data', function (data) { body += data; })  
                          .on('end', function () { console.log("push success =>"+data); });  
        }  
        else {  
            console.log("push fail =>"+serverFeedback.statusMessage); 
        }  
    });  
    req.write(data);
    req.end();
} 

module.exports = sendPush